package com.book.system.controller;

import com.book.common.annotation.Log;
import com.book.common.controller.BaseController;
import com.book.common.entity.FebsResponse;
import com.book.common.entity.QueryRequest;
import com.book.system.entity.Money;
import com.book.system.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class MoneyController extends BaseController {
    @Autowired
    MoneyService moneyService;

    @GetMapping("price")
    public FebsResponse priceView(Money money) {
        return new FebsResponse().data(this.moneyService.getMoney(money));
    }

    @Log("访问支付信息")
    @GetMapping("price/list")
    public FebsResponse pricePage(Money money, QueryRequest request) {
        Map<String, Object> dataTable = getDataTable(this.moneyService.getMoneyByPage(money, request));
        return new FebsResponse().success().data(dataTable);
    }

    @Log("支付信息-删除")
    @PostMapping("price/delete/{ids}")
    public FebsResponse deletePrice(@PathVariable String ids) {
        String[] attr = ids.split(",");
        List<Money> moneyList = moneyService.deleteMoney(attr);
        for (int i = 0; i < moneyList.size(); i++) {
            moneyList.get(i).setOmit("0");
            moneyService.updateMoney(moneyList.get(i));
        }
        return new FebsResponse().success();
    }
}